package com.gouaixin.bee.beeframework2.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ab.util.AbDialogUtil;
import com.ab.util.AbImageUtil;
import com.ab.util.AbToastUtil;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.google.gson.Gson;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.bean.USER;
import com.gouaixin.bee.beeframework2.bean.VipType;
import com.gouaixin.bee.beeframework2.component.DragImageView;
import com.gouaixin.bee.beeframework2.component.RoundImageView;
import com.gouaixin.bee.beeframework2.model.AttentionModel;
import com.gouaixin.bee.beeframework2.model.DialogModel;
import com.gouaixin.bee.beeframework2.model.EncodeIdModel;
import com.gouaixin.bee.beeframework2.model.HeightModel;
import com.gouaixin.bee.beeframework2.model.HelloModel;
import com.gouaixin.bee.beeframework2.model.MemberModel;
import com.gouaixin.bee.beeframework2.tool.PreferencesUtils;
import com.gouaixin.bee.beeframework2.tool.TimeUtil;
import com.gouaixin.bee.beeframework2.tool.XHttpUtils;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.listener.GetListener;
import cn.bmob.v3.listener.UpdateListener;

/**
 * Created by Administrator on 2015/3/9.
 */

//个人资料界面
public class B6_ziliaoActivity extends FragmentActivity {
    Context context=B6_ziliaoActivity.this;

    boolean isMe;//是否查看本人的资料
    boolean isVip=false;//是否是VIP



    //顶部
    ImageView back;//返回
    TextView title;//标题

    ImageView faxin;//发信
    ImageView zhaohu;//打招呼
    ImageView guanzhu;//关注
    ImageView shiping;//视频聊天

    //发信等的视图数组
    ImageView myTextView[]={faxin,zhaohu,guanzhu,shiping};

    //发信等的id数组
    int myID[]={R.id.faxin,R.id.zhaohu,R.id.guanzhu,R.id.shiping};

    RoundImageView icon;//头像
    TextView id,juli,genderMore,qianming,name,gender,age,address,hight,shouru,hunyin;//基本资料
    TextView qq,phone,weixin;//联系方式
    TextView xueli,zhiye,shengri,tizhong,xingzuo;//详细资料
    TextView ageTj,addressTj,hightTj,xueliTj,shouruTj;//征友条件

    TextView photo1,photo2,photo3,photo4,photo5;

    LinearLayout simi;



    List<BmobFile> xiangce = new ArrayList<BmobFile>();



    RelativeLayout juliMore;//距离所在的栏目

    //基本资料
    LinearLayout nameBt,genderBt,ageBt,addressBt,hightBt,shouruBt,hunyinBt;
    //联系方式
    LinearLayout qqBt,phoneBt,weixinBt;
    //详细资料
    LinearLayout xueliBt,zhiyeBt,shengriBt,weightBt,xingzuoBt;

    //征友条件
    LinearLayout ageFt,addressFt,hightFt,xueliFt,shouruFt;





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.b6_ziliao);

        //设置isDetailBack==true
        PreferencesUtils.putBoolean(context, "isDetailBack", true);

        cid = PreferencesUtils.getString(context, "cid", "");
        cname = PreferencesUtils.getString(context, "cname", "");


        initContentView();

        initIntent();

        initHead();


        initZaixian();



    }

    private void initZaixian() {

        TextView zaixianStr= (TextView) findViewById(R.id.zaixianStr);
        int sexType=PreferencesUtils.getInt(context,"sexType",0);
        mLog.e("我的性别：sexType="+sexType);
        if(sexType==0){
            zaixianStr.setText("她在线哦，快聊聊吧！");
        }else {
            zaixianStr.setText("他在线哦，快聊聊吧！");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initFudong();
    }


    /***
     * 获取内容区域的视图对象
     */
    private void initContentView() {
        icon= (RoundImageView) findViewById(R.id.icon);
        id= (TextView) findViewById(R.id.id);
        juli= (TextView) findViewById(R.id.juli);
        genderMore= (TextView) findViewById(R.id.genderMore);
        photo1= (TextView) findViewById(R.id.photo1);
        photo2= (TextView) findViewById(R.id.photo2);
        photo3= (TextView) findViewById(R.id.photo3);
        photo4= (TextView) findViewById(R.id.photo4);
        photo5= (TextView) findViewById(R.id.photo5);
        simi= (LinearLayout) findViewById(R.id.simi);
        qianming= (TextView) findViewById(R.id.qianming);

        name= (TextView) findViewById(R.id.name);
        gender= (TextView) findViewById(R.id.gender);
        age= (TextView) findViewById(R.id.age);
        address= (TextView) findViewById(R.id.address);
        hight= (TextView) findViewById(R.id.hight);
        shouru= (TextView) findViewById(R.id.shouru);
        hunyin= (TextView) findViewById(R.id.hunyin);

        qq= (TextView) findViewById(R.id.qq);
        phone= (TextView) findViewById(R.id.phone);
        weixin= (TextView) findViewById(R.id.weixin);

        xueli= (TextView) findViewById(R.id.xueli);
        zhiye= (TextView) findViewById(R.id.zhiye);
        shengri= (TextView) findViewById(R.id.shengri);
        tizhong= (TextView) findViewById(R.id.tizhong);
        xingzuo= (TextView) findViewById(R.id.xingzuo);

        ageTj= (TextView) findViewById(R.id.ageTj);
        addressTj= (TextView) findViewById(R.id.addressTj);
        hightTj= (TextView) findViewById(R.id.hightTj);
        xueliTj= (TextView) findViewById(R.id.xueliTj);
        shouruTj= (TextView) findViewById(R.id.shouruTj);

        juliMore= (RelativeLayout) findViewById(R.id.juliMore);

        nameBt= (LinearLayout) findViewById(R.id.nameBt);
        genderBt= (LinearLayout) findViewById(R.id.genderBt);
        ageBt= (LinearLayout) findViewById(R.id.ageBt);
        addressBt= (LinearLayout) findViewById(R.id.addressBt);
        hightBt= (LinearLayout) findViewById(R.id.hightBt);
        shouruBt= (LinearLayout) findViewById(R.id.shouruBt);
        hunyinBt= (LinearLayout) findViewById(R.id.hunyinBt);

        qqBt= (LinearLayout) findViewById(R.id.qqBt);
        phoneBt= (LinearLayout) findViewById(R.id.phoneBt);
        weixinBt= (LinearLayout) findViewById(R.id.weixinBt);

        xueliBt= (LinearLayout) findViewById(R.id.xueliBt);
        zhiyeBt= (LinearLayout) findViewById(R.id.zhiyeBt);
        shengriBt= (LinearLayout) findViewById(R.id.shengriBt);
        weightBt= (LinearLayout) findViewById(R.id.weightBt);
        xingzuoBt= (LinearLayout) findViewById(R.id.xingzuoBt);

        ageFt= (LinearLayout) findViewById(R.id.ageFt);
        addressFt= (LinearLayout) findViewById(R.id.addressFt);
        hightFt= (LinearLayout) findViewById(R.id.hightFt);
        xueliFt= (LinearLayout) findViewById(R.id.xueliFt);
        shouruFt= (LinearLayout) findViewById(R.id.shouruFt);

        String addressStr=PreferencesUtils.getString(context,"address","神秘城市");
        address.setText(addressStr);


    }

    /***
     * 获取传送过来的Intent对象
     */
    private void initIntent() {
        Intent mIntent=getIntent();
        isMe=mIntent.getBooleanExtra("isMe",false);
        HerId=mIntent.getStringExtra("HerId");
//        Herjuli=mIntent.getStringExtra("Herjuli");
//        Herhight=mIntent.getStringExtra("Herhight");
        if(!HerId.equals("")){
            Herjuli= HeightModel.getJuli(context, HerId);
            Herhight=HeightModel.getHeight(context, HerId);
            mLog.e("HerId=" + HerId);
            Log.e("test", "里面的Activity接受的数据：id=" + HerId + "\tjuli=" + Herjuli + "\theight=" + Herhight);
        }


    }

    /***
     * 头部的监听
     */
    private void initHead() {
        back= (ImageView) findViewById(R.id.head_left);
        title= (TextView) findViewById(R.id.head_title);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    /***
     *浮动图标的监听
     */
    private void initFudong() {

        RelativeLayout fudongTubiao= (RelativeLayout) findViewById(R.id.fudongTubiao);
        if(isMe){
            fudongTubiao.setVisibility(View.GONE);
            juliMore.setVisibility(View.GONE);
            getMyData();//得到个人信息
        }else {
            fudongTubiao.setVisibility(View.VISIBLE);
            getHerData();//得到对象信息
            juliMore.setVisibility(View.VISIBLE);

        }

        for(int i=0;i<myTextView.length;i++){
            myTextView[i]= (ImageView) this.findViewById(myID[i]);
        }

        faxin= (ImageView) fudongTubiao.findViewById(R.id.faxin);
        zhaohu= (ImageView) fudongTubiao.findViewById(R.id.zhaohu);
        guanzhu= (ImageView) fudongTubiao.findViewById(R.id.guanzhu);
        shiping= (ImageView) fudongTubiao.findViewById(R.id.shiping);

        isZhaohu=PreferencesUtils.getBoolean(context,HerId+"isZhaohu",false);
        isGuanzhu=PreferencesUtils.getBoolean(context,HerId+"isGuanzhu",false);

        refreshFudong();

        for (ImageView ll : myTextView) {
            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        switch (v.getId()) {
                            case R.id.faxin:
//                                Toast.makeText(context,"发信"+"功能正在开发中",Toast.LENGTH_SHORT).show();
                                faxin();
                                break;
                            case R.id.zhaohu:
//                                Toast.makeText(context,"打招呼"+"功能正在开发中",Toast.LENGTH_SHORT).show();
                                dazhaohu();
                                break;
                            case R.id.guanzhu:
//                                Toast.makeText(context,"关注"+"功能正在开发中",Toast.LENGTH_SHORT).show();
                                guanzhu();
                                break;
                            case R.id.shiping:
//                                Toast.makeText(context,"关注"+"功能正在开发中",Toast.LENGTH_SHORT).show();
                                shipingLiaotian();
                                break;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }



    }

    /***
     * 视频聊天的方法
     */
    private void shipingLiaotian() {

        //1.判断是否是VIP用户
        boolean isVIP= PreferencesUtils.getBoolean(context,"isVIP",false);

        //2.是VIP
        if(isVIP){
            mLog.e("进入附近的人界面");
            Intent it = new Intent().setClass(context, B6_ziliaoActivity.class);
            it.putExtra("flag","fujin");
            it.putExtra("name","VIP");
            startActivity(it);
        }
        //3.非VIP
        else{
            mLog.e("弹出VIP服务对话框");


            View mView = LayoutInflater.from(context).inflate(R.layout.dialog_vipfuwu, null);
            AbDialogUtil.showDialog(mView);

            TextView content= (TextView) mView.findViewById(R.id.content);
            TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
            TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

            content.setText("你还没有开通VIP，无法视频聊天！");

            quxiao.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AbDialogUtil.removeDialog(context);
                }
            });
            kaitong.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent it = new Intent().setClass(context, B14_vipTequanActivity.class);
                    startActivity(it);
                    AbDialogUtil.removeDialog(context);
                }
            });

        }


    }

    String HerId="";//机器人id
    String Herjuli="";//机器人距离
    String Herhight="";//机器人身高
    String jicon="";//机器人icon
    String jname="";//机器人name

    /***
     * 发信功能的实现
     *
     */
    private void faxin() {
        mLog.e("jid=" + HerId);
        mLog.e("jname=" + name.getText().toString());
        mLog.e("jicon=" + jicon);
        mLog.e("qianming=" + qianming.getText().toString());

        Intent it = new Intent().setClass(context, C2_MsgActivity.class);
        it.putExtra("jid", HerId);
        it.putExtra("jname",name.getText().toString());
        it.putExtra("jicon", jicon);
        it.putExtra("qianming", qianming.getText().toString());
        it.putExtra("flag", "1");
        startActivity(it);




    }

    /***
     * 打招呼功能的实现
     */
    private void dazhaohu() {
        mLog.e("点击了打招呼");
        mLog.e("isZhaohu=" + isZhaohu);
        mLog.e("jid=" + HerId);
        mLog.e("jicon=" + jicon);
        mLog.e("cid=" + cid);
        mLog.e("jname=" + jname);


        if(isZhaohu==false){
            HelloModel.oneZhaohu(context, HerId, jicon, cid, jname);

            //判断是否可以打招呼
            boolean hasZhaohu=PreferencesUtils.getBoolean(context,"hasZhaohu",false);
            if(hasZhaohu==true){
                return;
            }

            AbToastUtil.showToast(context, "打招呼成功！");
            PreferencesUtils.putBoolean(context, HerId + "isZhaohu", true);
            isZhaohu=PreferencesUtils.getBoolean(context,HerId+"isZhaohu",false);
            refreshFudong();//刷新浮动图标

//            String text = "你好，可以和我聊聊吗？";
//            String time =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
////                    addMessage(finalId, cid, text, time,position);
//            BaseModel.setCallBackLister(new BaseModel.CallBackLister() {
//                @Override
//                public void onCallBack(String url, String data) {
//                    AbToastUtil.showToast(context, "打招呼成功！");
//                    PreferencesUtils.putBoolean(context, HerId + "isZhaohu", true);
//                    isZhaohu=PreferencesUtils.getBoolean(context,HerId+"isZhaohu",false);
//                    refreshFudong();//刷新浮动图标
//                }
//            });
//
//            RequestParams params=new RequestParams();
//            params.addBodyParameter("id", HerId);
//            params.addBodyParameter("cid", cid);
//            params.addBodyParameter("text", text);
//            params.addBodyParameter("time", time);
//            BaseModel.post(MyAPI.addchatfriend,params);

        }else {
            AbToastUtil.showToast(context, "已打招呼！");
        }

    }

    /***
     * 关注功能的实现
     */
    private void guanzhu() {
        mLog.e("点击了打招呼");
        mLog.e("isGuanzhu=" + isGuanzhu);
        mLog.e("jid=" + HerId);
        mLog.e("jicon=" + jicon);
        mLog.e("cid=" + cid);
        mLog.e("cname=" + cname);

        if(isGuanzhu==false) {
            AttentionModel.addGuanzhu(context, HerId, jicon, cid);
            AbToastUtil.showToast(context, "添加关注成功");
            PreferencesUtils.putBoolean(context,HerId+"isGuanzhu",true);
            isGuanzhu=PreferencesUtils.getBoolean(context,HerId+"isGuanzhu",false);
            refreshFudong();//刷新浮动图标

//            BaseModel.setCallBackLister(new BaseModel.CallBackLister() {
//                @Override
//                public void onCallBack(String url, String data) {
//                    AbToastUtil.showToast(context, "添加关注成功");
//                    PreferencesUtils.putBoolean(context,HerId+"isGuanzhu",true);
//                    isGuanzhu=PreferencesUtils.getBoolean(context,HerId+"isGuanzhu",false);
//                    refreshFudong();//刷新浮动图标
//                }
//            });
//            RequestParams params = new RequestParams();
//            params.addBodyParameter("id", HerId);
//            params.addBodyParameter("cid", cid);
//            BaseModel.post(MyAPI.addguanzhu, params);
        }else {
            AbToastUtil.showToast(context, "已添加关注");
        }

    }

    /***
     * 得到个人详情
     * @return
     */
    private void getMyData() {
        BmobQuery<USER> query = new BmobQuery<USER>();
        query.getObject(context, BmobUser.getCurrentUser(context).getObjectId(), new GetListener<USER>() {
            @Override
            public void onSuccess(USER user) {
                setMyData(user);
            }

            @Override
            public void onFailure(int i, String s) {

            }
        });

    }



    JSONArray jsonArray=new JSONArray();//对象详情的json
    String result = "";
    /***
     * 得到对象详情
     * @return
     */
    public  void getHerData() {
        String url="http://jiekou.hydgyx.com/api/interface_detail.php";

        RequestParams params = new RequestParams();
        params.addBodyParameter("id", HerId);
        params.addBodyParameter("cid", PreferencesUtils.getString(context,"cid"));

        mLog.e("id=" + HerId);
        mLog.e("cid=" + PreferencesUtils.getString(context, "id"));

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST,
                url,
                params,
                new RequestCallBack<String>() {

                    @Override
                    public void onStart() {
                        mLog.e("conn...");
                    }

                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                        if (isUploading) {
                            mLog.e("upload: " + current + "/" + total);
                        } else {
                            mLog.e("reply: " + current + "/" + total);
                        }
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        mLog.e("得到对象详情：响应值：reply: " + responseInfo.result);
                        result=responseInfo.result;
                        setHerData(result);//初始化对象信息
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        mLog.e(error.getExceptionCode() + ":" + msg);
                    }
                });
    }

    LinearLayout lianxifangshi;
    /***
     * 设置对象信息
     * @param json
     */
    private void setHerData(String json) {
        title.setText(HerId);


        lianxifangshi= (LinearLayout) findViewById(R.id.lianxifangshi);

        MemberModel.setGetUserLister(new MemberModel.GetUserLister() {
            @Override
            public void onSuccess(USER user) {
                long vipEndTime = user.getVipEndTime();
                long currentTime = TimeUtil.getCurrentTime();
                if (currentTime <= vipEndTime) {
                    isVip = true;
                    mLog.e("我是VIP");
                    simi.setVisibility(View.GONE);
                    shiping.setVisibility(View.GONE);
                    lianxifangshi.setVisibility(View.GONE);


                } else {
                    isVip = false;
                    MemberModel.vipSuccess(context, VipType.Type_0);
                    mLog.e("我不是VIP");
                    simi.setVisibility(View.VISIBLE);
                    shiping.setVisibility(View.VISIBLE);
                    lianxifangshi.setVisibility(View.VISIBLE);

                }

            }

            @Override
            public void onFailure(int i, String s) {

            }
        });
        MemberModel.getUSER(context);


        photo4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context,"弹出VIP对话框");
                DialogModel.goVIP(context, "你还没有开通VIP，无法查看TA的视频");

            }
        });

        photo5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context,"弹出VIP对话框");
                DialogModel.goVIP(context, "你还没有开通VIP，无法查看隐私照片");

            }
        });


        try {
            JSONObject jsonOb = new JSONObject (json);
            if (jsonOb != null) {

                qianming.setText(jsonOb.getString("qianming"));
                name.setText(jsonOb.getString("name"));

//                    hight.setText(jsonOb.getString("height"));
                try{
//                    if(Herhight==null||Herhight.endsWith("")||Herhight.endsWith("null")){
//                        Herhight=jsonOb.getString("height");
////                        Herhight="166CM";
//                        Log.e("height","Herhight"+"为空");
//                    }
                    hight.setText(HeightModel.getHeight(context,HerId));
                } catch (Exception e) {
                    mLog.e("height解析异常：" + e.getMessage());
                }


                age.setText(jsonOb.getString("age"));
//                    address.setText("武汉市");


                title.setText(jsonOb.getString("name"));
                String url = jsonOb.getString("icon");
                jicon=url;
                jname=jsonOb.getString("name");
                if(url!=null||!url.equals("")){
//                        ImageLoader.getInstance().displayImage(url, icon);

                    try{
                        ImageLoader.getInstance().displayImage(jicon, icon,new ImageLoadingListener() {
                            @Override
                            public void onLoadingStarted(String s, View view) {

                            }

                            @Override
                            public void onLoadingFailed(String s, View view, FailReason failReason) {
                                mLog.e("加载详情头像：错误=" + s);

                                if(s.endsWith(".jpg")){
                                    mLog.e("将jpg转png");
                                    s=s.replaceAll(".jpg",".png");
                                }
                                else if(s.endsWith(".png")){
                                    mLog.e("将png转jpg");
                                    s=s.replaceAll(".png",".jpg");
                                }

                                mLog.e("加载详情头像：转化后的jicon=" + s);

                                ImageLoader.getInstance().displayImage(s,icon);

                            }

                            @Override
                            public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                                mLog.e("加载详情头像：成功=" + s);

                            }

                            @Override
                            public void onLoadingCancelled(String s, View view) {

                            }
                        });
                    }
                    catch (Exception e){
                        mLog.e("加载详情头像：捕获错误=" + e.getMessage());
                    }

                }
                else {
//                        icon.setImageResource(R.drawable.ic_other_avatar_status02);
                    icon.setImageResource(R.drawable.mylogo);
                }





                //生成新id
                String newid= EncodeIdModel.encodeId(HerId);

                //解码新id
                String aaa=EncodeIdModel.decodeId(newid);


                id.setText("id:"+newid);
//                    id.setText("id:"+MyAPI.idQianZui+HerId);

//                    juli.setText(jsonOb.getString("juli"));
                juli.setText(Herjuli);


                final JSONArray jsonArray1 = jsonOb.getJSONArray("photo");
                for (int i = 0; i < jsonArray1.length(); i++) {
                    BitmapUtils bitmapUtils=new BitmapUtils(context);

                    switch (i){
                        case 0:
                            bitmapUtils.display(photo1,jsonArray1.opt(i).toString());
                            final int finalI = i;
                            photo1.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    show(photo1);
                                }
                            });
//                                ImageLoader.getInstance().displayImage(jsonArray1.opt(i).toString(),  photo1);
                            break;
                        case 1:
                            bitmapUtils.display(photo2,jsonArray1.opt(i).toString());
                            photo2.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    show(photo2);
                                }
                            });
//                                ImageLoader.getInstance().displayImage(jsonArray1.opt(i).toString(),  photo2);
                            break;
                        case 2:
                            bitmapUtils.display(photo3,jsonArray1.opt(i).toString());//
                            photo3.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    show(photo3);
                                }
                            });
                            //ImageLoader.getInstance().displayImage(jsonArray1.opt(i).toString(),  photo3);
                            break;
                    }
                }




//
//                    if(!jsonOb.getString("region").equals("")&&jsonOb.getString("region")!=null){
//                        address.setText(jsonOb.getString("region"));
//                    }

                name.setText(jsonOb.getString("name"));
                gender.setText(jsonOb.getString("gender"));
                age.setText(jsonOb.getString("age"));

//                    if(!jsonOb.getString("region").equals("")&&jsonOb.getString("region")!=null){
//                        address.setText(jsonOb.getString("region"));
//                    }

//                    if(!jsonOb.getString("height").equals("")&&jsonOb.getString("height")!=null){
//                        hight.setText(jsonOb.getString("height"));
//                    }

                hight.setText(Herhight);

                if(!jsonOb.getString("hunyin").equals("")&&jsonOb.getString("hunyin")!=null){
                    hunyin.setText(jsonOb.getString("hunyin"));
                }

                if(!jsonOb.getString("qq").equals("")&&jsonOb.getString("qq")!=null){
                    qq.setText(jsonOb.getString("qq"));
                }

                if(!jsonOb.getString("weixin").equals("")&&!jsonOb.getString("weixin").equals("null")&&jsonOb.getString("weixin")!=null){
                    weixin.setText(jsonOb.getString("weixin"));
                }

                if(!jsonOb.getString("phone").equals("")&&jsonOb.getString("phone")!=null){
                    phone.setText(jsonOb.getString("phone"));
                }


                if(!jsonOb.getString("xueli").equals("")&&!jsonOb.getString("xueli").equals("null")&&jsonOb.getString("xueli")!=null){
                    xueli.setText(jsonOb.getString("xueli"));
                }

                if(!jsonOb.getString("zhiye").equals("")&&!jsonOb.getString("zhiye").equals("null")&&jsonOb.getString("zhiye")!=null){
                    zhiye.setText(jsonOb.getString("zhiye"));
                }

                if(!jsonOb.getString("shengri").equals("")&&jsonOb.getString("shengri")!=null){
                    shengri.setText(jsonOb.getString("shengri"));
                }

                if(!jsonOb.getString("tizhong").equals("")&&jsonOb.getString("tizhong")!=null){
                    tizhong.setText(jsonOb.getString("tizhong"));
                }

                if(!jsonOb.getString("xingzuo").equals("")&&jsonOb.getString("xingzuo")!=null){
                    xingzuo.setText(jsonOb.getString("xingzuo"));
                }

                JSONObject filter = jsonOb.getJSONObject("filter");
//                    String ageStart="不限";
//                    if(!filter.getString("AgeStart").equals("")&&filter.getString("AgeStart")!=null){
//                        ageStart=filter.getString("AgeStart");
//                    }
//                    String ageEnd="不限";
//                    if(!filter.getString("AgeEnd").equals("")&&filter.getString("AgeEnd")!=null){
//                        ageEnd=filter.getString("AgeEnd");
//                    }
//                    ageTj.setText(ageStart+"~"+ageEnd);

                if(!filter.getString("age").equals("")&&filter.getString("age")!=null){
                    ageTj.setText(filter.getString("age"));
                }
                if(!filter.getString("xueli").equals("")&&filter.getString("xueli")!=null){
                    xueliTj.setText(filter.getString("xueli"));
                }

                if(!filter.getString("height").equals("")&&filter.getString("height")!=null){
                    hightTj.setText(filter.getString("height"));
                }


//                    String ageEnd="不限";
//                    if(!filter.getString("AgeEnd").equals("")&&filter.getString("AgeEnd")!=null){
//                        ageEnd=filter.getString("AgeEnd");
//                    }
//                    ageTj.setText(ageStart+"~"+ageEnd);


                Herhight=HeightModel.getHeight(context,HerId);
                String genderMoreStr=jsonOb.getString("gender")+","+jsonOb.getString("age")+","+Herhight+"";

                genderMore.setText(genderMoreStr);







            }


        } catch (Exception e) {
            e.printStackTrace();
            mLog.e("json解析异常：" + e.getMessage());
        }

    }



    boolean isZhaohu;
    boolean isGuanzhu;
    String cid="";
    String cname="";
    /***
     * 刷新浮动图标
     */
    private void refreshFudong() {
        mLog.e("刷新打招呼");
        mLog.e("isZhaohu=" + isZhaohu);
        if(isZhaohu==false){
            zhaohu.setBackgroundResource(R.drawable.userinfo_sayhello);


        }else {
            zhaohu.setBackgroundResource(R.drawable.userinfo_no_sayhello);
        }

        if(isGuanzhu==false){
            guanzhu.setBackgroundResource(R.drawable.userinfo_followed);

        }else {
            guanzhu.setBackgroundResource(R.drawable.userinfo_no_followed);
        }


    }


    /***
     * 设置个人信息
     * @param user
     */
    private void setMyData(USER user) {

        simi.setVisibility(View.GONE);

        mLog.e("设置个人信息:" + new Gson().toJson(user));

        final USER myuser = user;
        BmobFile micon = myuser.getIcon();
        if (micon != null) {
            String url = micon.getFileUrl(context);
            ImageLoader.getInstance().displayImage(url, icon);
        } else {
            icon.setImageResource(R.drawable.ic_user_avatar_default);
        }
        mLog.e("name:" + myuser.getName());
        mLog.e("id:" + myuser.getUsername());
        title.setText(myuser.getName());
        if( myuser.getIcon()!=null){
            String url = myuser.getIcon().getFileUrl(context);
            ImageLoader.getInstance().displayImage(url, icon);
        }
        id.setText("ID:" + myuser.getUsername());

        if(myuser.getQianming()!=null){
            qianming.setText(myuser.getQianming());
        }

        TextView[] xiangceTv={photo1,photo2,photo3};


        xiangce=user.getXiangce();
        if(xiangce!=null&&xiangce.size()!=0){
            for(int i=0;i<xiangce.size()&&i<3;i++){

                BitmapUtils bitmapUtils=new BitmapUtils(context);
                bitmapUtils.display(xiangceTv[i],xiangce.get(i).getFileUrl(context));

            }
        }



        //显示基本资料
        name.setText(myuser.getName());
        gender.setText(myuser.getGender());
        age.setText(myuser.getAge());

        if(myuser.getRegion()!=null){
            address.setText(myuser.getRegion());
        }

        if(myuser.getHeight()!=null){
            hight.setText(myuser.getHeight());
        }

        if(myuser.getShouru()!=null){
            shouru.setText(myuser.getShouru());
        }

        if(myuser.getHunyin()!=null){
            hunyin.setText(myuser.getHunyin());
        }

        if(myuser.getQq()!=null){
            qq.setText(myuser.getQq());
        }

        if(myuser.getPhone()!=null){
            phone.setText(myuser.getPhone());
        }


        if(myuser.getWeixin()!=null||!myuser.getWeixin().equals("null")){
            weixin.setText(myuser.getWeixin());
        }


        if(myuser.getXueli()!=null){
            xueli.setText(myuser.getXueli());
        }

        if(myuser.getZhiye()!=null||!myuser.getWeixin().equals("null")){
            zhiye.setText(myuser.getZhiye());
        }

        if(myuser.getShengri()!=null){
            shengri.setText(myuser.getShengri());
        }

        if(myuser.getTizhong()!=null){
            tizhong.setText(myuser.getTizhong());
        }

        if(myuser.getXingzuo()!=null){
            xingzuo.setText(myuser.getXingzuo());
        }

        //显示征友条件
        if(myuser.getAgeft()!=null){
            ageTj.setText(myuser.getAgeft());
        }
        if(myuser.getAddressft()!=null){
            addressTj.setText(myuser.getAddressft());
        }
        if(myuser.getHightft()!=null){
            hightTj.setText(myuser.getHightft());
        }
        if(myuser.getXuelift()!=null){
            xueliTj.setText(myuser.getXuelift());
        }
        if(myuser.getShouru()!=null){
            shouruTj.setText(myuser.getShouru());
        }

        resetJibenZiliao(myuser);//修改基本资料
        resetXiangxiZiliao(myuser);//修改详细资料
        resetLianxiFangshi(myuser);//修改联系方式
        resetZhengyouTiaojian(myuser);//修改征友条件














    }

    //修改征友条件
    private void resetZhengyouTiaojian(final USER myuser) {
        ageFt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("年龄");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setAgeft(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        addressFt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("居住地");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setAddressft(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        hightFt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("身高");

                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setName(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        xueliFt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("学历");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setName(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        shouruFt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("月收入");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setShouruft(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });



    }

    //修改联系方式
    private void resetLianxiFangshi(final USER myuser ) {
        qqBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                if(myuser.getQq()!=null){
                    edit.setText(myuser.getQq());
                }
                title.setText("QQ");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setQq(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


        phoneBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                if(myuser.getPhone()!=null){
                    edit.setText(myuser.getPhone());
                }
                title.setText("手机");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setPhone(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


        weixinBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                if(myuser.getWeixin()!=null){
                    edit.setText(myuser.getWeixin());
                }
                title.setText("微信");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setWeixin(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

    }

    //修改详细资料
    private void resetXiangxiZiliao(final USER myuser) {
        xueliBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("学历");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setXueli(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        zhiyeBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("职业");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setZhiye(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        shengriBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("生日");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setShengri(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        weightBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("体重");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setTizhong(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        xingzuoBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("星座");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setXingzuo(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


    }

    //修改基本资料
    private void resetJibenZiliao(final USER myuser) {
        nameBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("昵称");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setName(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });

        genderBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AbToastUtil.showToast(context,"性别无法修改");

            }
        });

        ageBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("年龄");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setAge(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


        addressBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("居住地");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setRegion(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


        hightBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("身高");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setHeight(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });


        shouruBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("月收入");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setShouru(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });



        hunyinBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLog.e("修改用户信息");

                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_ziliaoedit, null);
                AbDialogUtil.showDialog(mView);

                TextView title= (TextView) mView.findViewById(R.id.title);
                final EditText edit= (EditText) mView.findViewById(R.id.edit);
                TextView quxiao= (TextView) mView.findViewById(R.id.quxiao);
                TextView kaitong= (TextView) mView.findViewById(R.id.kaitong);

                title.setText("婚姻状态");


                quxiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(context);
                    }
                });
                kaitong.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mLog.e("修改用户信息：开始实现");
                        String str=edit.getText().toString();
                        if(str.equals("")){
                            AbToastUtil.showToast(context,"输入内容不能为空");
                            return;
                        }
                        USER myuser = BmobUser.getCurrentUser(context, USER.class);
                        myuser.setHunyin(str);
                        myuser.update(context, new UpdateListener() {
                            @Override
                            public void onSuccess() {
                                AbToastUtil.showToast(context, "更新用户信息成功");
                                AbDialogUtil.removeDialog(context);
                                getMyData();
                            }

                            @Override
                            public void onFailure(int i, String s) {
                                AbToastUtil.showToast(context, "更新用户信息失败："+s);
                                AbDialogUtil.removeDialog(context);

                            }
                        });



                    }
                });

            }
        });






    }

    /***
     * 得到查看的用户详情
     * @return
     */
    public  String getTuijian() {
        String url="http://jiekou.hydgyx.com/api/interface_detail.php";
        final String[] result = {""};

        RequestParams params = new RequestParams();
        params.addBodyParameter("id", "203");//1.用户的id

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST,
                url,
                params,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                        mLog.e(current + "/" + total);
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        mLog.e("请求成功：" + XHttpUtils.Unicode2Chinese(responseInfo.result));
                        result[0] =XHttpUtils.Unicode2Chinese(responseInfo.result);

//                        try {
//                            jsonArray=new JSONArray(result[0]);
//                            mAdapter.setJson(jsonArray);
//                            mAdapter.notifyDataSetChanged();
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
                    }

                    @Override
                    public void onStart() {
                        mLog.e("开始请求：");
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        mLog.e("请求故障：" + msg);
                    }
                }
        );
        return result[0];
    }

    //显示可缩放图片
    public  void show(View view){
//        View mView = LayoutInflater.from(context).inflate(R.layout.dialog_photo, null);
//        AbDialogUtil.showDialog(mView);
//
//        DragImageView xphoto= (DragImageView) mView.findViewById(R.id.xphoto);

//        BitmapUtils bitmapUtils=new BitmapUtils(context);

        Drawable drawable=view.getBackground();
        if(drawable!=null){

            Bitmap bmp=AbImageUtil.drawableToBitmap(drawable);
//        initPhoto(xphoto,bmp);

            mLog.e("跳转到缩放界面");
            Intent it=new Intent(context,showPhotoActivity.class);
            it.putExtra("bitmap", bmp);
            startActivity(it);

        }


    }


    //--------------------【可缩放ImageView:START】------------------------------------------
    private int window_width, window_height;// �ؼ����
    private DragImageView dragImageView;// �Զ���ؼ�
    private int state_height;// ״̬���ĸ߶�

    private ViewTreeObserver viewTreeObserver;

    private void initPhoto(final DragImageView dragImageView,Bitmap bmp) {
        /** ��ȡ��Ҋ����߶� **/
        WindowManager manager = getWindowManager();
        window_width = manager.getDefaultDisplay().getWidth();
        window_height = manager.getDefaultDisplay().getHeight();

//        Bitmap bmp = BitmapUtil.ReadBitmapById(this, R.drawable.mylogo,
//                window_width, window_height);
        // ����ͼƬ
        dragImageView.setImageBitmap(bmp);
        dragImageView.setmActivity(this);//ע��Activity.
        /** ����״̬���߶� **/
        viewTreeObserver = dragImageView.getViewTreeObserver();
        viewTreeObserver
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {
                        if (state_height == 0) {
                            // ��ȡ״�����߶�
                            Rect frame = new Rect();
                            getWindow().getDecorView()
                                    .getWindowVisibleDisplayFrame(frame);
                            state_height = frame.top;
                            dragImageView.setScreen_H(window_height-state_height);
                            dragImageView.setScreen_W(window_width);
                        }

                    }
                });

    }


    public static Bitmap ReadBitmapById(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        // ��ȡ��ԴͼƬ
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }

    //--------------------【可缩放ImageView:END】---------------------------------------------

}
